﻿
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Index</title>
    <link href="~/layui/css/layui.css" rel="stylesheet" />

</head>
<body>
    <div class="layui-fluid main">
        <!--主要内容开始-->
        <table class="layui-table" lay-size="sm" style="margin-bottom:-11px; background:#F5F5F5">
            <tr>
                <td>
                    <div class="left1">
                        <form id="FrmSearch" name="FrmSearch" class="layui-form xxasp_x630">
                            <span class="layui-input-inline" style="width:280px;">
                                <input id="Keywords" name="Keywords" type="text" class="layui-input" placeholder="关键字查询" value="">
                            </span>
                            <span class="layui-input-inline">
                                <button class="layui-btn layui-btn-normal" id="tableSearch"><i class="layui-icon">&#xe615;</i> 检索 </button>
                                <button type="button" class="layui-btn layui-btn-sm" onclick="add(0,'');">添加党支部</button>
                            </span>
                        </form>
                    </div>
                </td>
            </tr>
        </table>

    </div>

    <div style="padding-left:10px;padding-right:10px;">
        <table class="layui-hidden" id="treeTable" lay-filter="treeTable"></table>
    </div>
</body>
</html>
<script src="~/layui/layui.js"></script>
<script>
    var editObj = null, ptable = null, treeGrid = null, tableId = 'treeTable', layer = null;
    layui.config({
        base: '/layui/extend/'
    }).extend({
        treeGrid: 'treeGrid'
    }).use(['jquery', 'treeGrid', 'layer'], function () {
        var $ = layui.jquery;
        treeGrid = layui.treeGrid;//很重要
        layer = layui.layer;
        ptable = treeGrid.render({
            id: tableId
            , elem: '#' + tableId
            , method:"get"
            , idField: 'Id'
            , url: '/json/list.json'
            , cellMinWidth: 100
            , treeId: 'Id'//树形id字段名称
            , treeUpId: 'ParentID'//树形父id字段名称
            , treeShowName: 'Name'//以树形式显示的字段
            , cols: [[
                { field: 'Name', width: 400, title: '党支部名称' }
                , { field: 'Id', width: 120, title: 'Id' }
                , { field: 'ParentID', width: 120, title: 'ParentID' }
                , {
                    title: '操作', align: 'center'/*toolbar: '#barDemo'*/
                    , templet: function (d) {
                        var html = '';
                        var addBtn = '<a class="layui-btn layui-btn-xs" onclick="add(' + d.Id + ',\'' + d.Name + '\')">添加下级</a>';
                        var editBtn = '<a class="layui-btn layui-btn-normal layui-btn-xs" onclick="edit(' + d.Id + ')">修改</a>';
                        var delBtn = '<a class="layui-btn layui-btn-danger layui-btn-xs" onclick="del(' + d.Id + ')">删除</a>';
                        return addBtn + editBtn + delBtn;
                    }
                }
            ]]
            , page: false
        });
    });

    function add(id, name) {
        xxasp_show('添加党支部', '/PartyBuild/Add?pid=' + id
            + "&parentName=" + name, true, 650, 450, 'auto', true)
    }

    function edit(id) {
        xxasp_show('修改党支部', '/PartyBuild/edit?id=' + id, true, 650, 450, 'auto', true)
    }

    function del(id) {
        layer.confirm("你确定删除数据吗？如果存在下级节点则一并删除，此操作不能撤销！", { icon: 3, title: '提示' },
            function (index) {//确定回调
                $.post('/PartyBuild/Delete?id=' + id, {}, function (result) {
                    layer.alert(result.Message);
                    if (result.Status)
                        reloadTable();
                }, "json");

                layer.close(index);
            }, function (index) {//取消回调
                layer.close(index);
            }
        );
    }


    function reloadTable(pageindex) {

        if (pageindex == undefined) {
            pageindex = 1;
        }

        var data = {};
        var t = $('#FrmSearch').serializeArray();

        $.each(t, function () {
            data[this.name] = this.value;
        });

        treeGrid.reload(tableId, {
            where: data
        });
    }
</script>